<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<title>管理中心</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="/sys-admin/css/general.css" rel="stylesheet" type="text/css">
<link href="/sys-admin/css/main.css" rel="stylesheet" type="text/css">
<script src="/sys-admin/js/jquery.js" type="text/javascript"></script>
<script src="/sys-admin/js/cn_message.js" type="text/javascript"></script>
<script src="/sys-admin/js/validate.js" type="text/javascript"></script>
</head>
<body>
<h1><span class="action-span1">模板添加</span></h1>
<div class="list-div">
<form action="/sys-admin/action/cms/template.php" method="post">
<input type="hidden" name="met" value="edit"/>
<input type="hidden" name="id" value="<{$template.tp_id}>"/>
<table>
 <tr>
    <td class="label"><span class="require-field">*</span>名称</td>
    <td><input type="text" name="name" maxlength="40" value="<{$template.tp_name}>" size="20" vtype="required" vname="template_add_name"/><span id="template_add_name_m"></span></td>
 </tr>
 <tr>
    <td class="label">文件名</td>
    <td id="f_name"><{$template.file_name}></td>
 </tr>
 <tr>
    <td class="label">文件路劲</td>
    <td id="f_path"><{$template.tp_path}><input type="button" value="修改模板 " class="button" onclick="popEditTpFile(<{$template.tp_id}>);"/></td>
 </tr>
 <tr>
    <td class="label"><span class="require-field">*</span>类型</td>
    <td><select name="type">
    <option value="1" <{if $template.tp_type eq 1}>selected="selected"<{/if}>>独立</option>
    <option value="2" <{if $template.tp_type eq 2}>selected="selected"<{/if}>>共用</option>
    </select>
	</td>
</tr>
<tr>
    <td class="label"></td>
    <td><input type="submit" value="修改 " class="button" onclick="return checkForm();"/>&nbsp;&nbsp;&nbsp;</td>
</tr>
</table>
</form>
</div>
<script src="/sys-admin/js/common.js" type="text/javascript"></script>
<script src="/sys-admin/js/jquery.form.js" type="text/javascript"></script>
<script type="text/javascript">
//修改背面图
function popEditTpFile(tpid){
	if(tpid > 0){
		var filename = $('#f_name').html();
		var html = '<form action="/sys-admin/action/cms/template.php" method="post" enctype="multipart/form-data" id="edit_tp_file">'
		   +'<input type="hidden" name="met" value="edittemplatefile"/>'
		   +'<input type="hidden" name="tpid" value="'+tpid+'"/>'
		   +'文件名：<input type="text" name="filename" maxlength="40" size="20" id="tp_fname" value="'+filename+'" vmin="0" vmax="20"/>'
		   +'<p>模　板： <input type="file" name="tpfile" id="tp_file"/></p>'
		   +'<input class="button" type="button" value="修改 " onclick="editTpfile();">'
		   +'</form>';
	 	popDailog('模板文件修改',html,190);
	}
}

function editTpfile(){
	if(!Fun.requiredLetterDigitalCheck($('#tp_fname'))){
		alert('模板名必须是不超过20位数字、字母');
		return;
	}
	if(!Fun.isEmpty($('#tp_file'))){
		alert('模板文件不能为空');
		return;
	}
	$('#edit_tp_file').ajaxSubmit({
		success:function(html){
			html = $.trim(html);
			var json = eval('('+html+')');
			if(json.code == 1){
				$('#f_name').html(json.name);
				$('#f_path').html(json.path);
				closeUpImg();
				alert('模板文件修改成功');
			}else if(json.code == 2){
				alert('模板文件不能超过1M');
			}else if(json.code == 3){
				alert('模板文件名已被占用');
			}else if(json.code == 4){
				alert('模板文件格式错误');
			}else{
				alert('模板文件修改失败');
			}
		}
	});
}


</script>
</body></html>